package com.ytjj.qmyx.admin.controller.supplyChain;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.api.CommonResult;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.admin.config.SupplyApiConfig;
import com.ytjj.qmyx.admin.model.request.ExpressOrderRequest;
import com.ytjj.qmyx.mall.model.ExpressDic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 快递管理(供应链)
 *
 * @version 1.0
 *
 */
@RestController
@RequestMapping("/expressBySupplyChain")
@Slf4j
public class ExpressBySupplyChainController {

    @Resource
    private SupplyApiConfig supplyApiConfig;

    /**
     * 获取快递订单列表
     * @param request
     * @return
     */
    @PostMapping("/getExpressOrdersList")
    public String getExpressOrdersList(@RequestBody ExpressOrderRequest request){
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/express/getExpressOrdersList",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
        return s;
    }

    /**
     * 获取快递公司列表
     */
    @GetMapping("/getCompany")
    public CommonResult getCompany(){
        String result = HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/order/getExpressDic", null, supplyApiConfig.getHeadsMap());
        List<ExpressDic> yxExpressDicList = JSONObject.parseArray(result, ExpressDic.class);
        return CommonResult.success(yxExpressDicList);
    }

    /**
     * 标记快递为无效
     * @return
     */
    @PostMapping("/markInvalidExpress")
    public String markInvalidExpress(@RequestBody List<Integer> expressIds){
        String result = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/express/markInvalidExpress",
                JSONObject.toJSONString(expressIds), supplyApiConfig.getHeadsMap());
        return result;
    }
}
